function []=checkdata(ExpID)

%% initialize
tmp_data_dir = ImageAnalysis.Settings.TempDataDir;
adata_dir = ImageAnalysis.Settings.AdataDir;

%% find the data file
[adata_file,mouse_id,date_id]=find_adata_file(ExpID,adata_dir);
disp(['___________' num2str(ExpID) '___________'] )

[~,~,stacks]=xlsread(ImageAnalysis.Settings.ExcelFile);
cnt=0;
for ind=1:size(stacks,1)
    if stacks{ind,7}==ExpID
        cnt=cnt+1;
        stacks_ind(cnt)=ind;
    end
end
if exist('stacks_ind','var')
    ExpIDs=stacks(stacks_ind,5);
else
    fprintf(2,'No matching entry in stacks.xls found. Aborting');
    disp(' ')
    return
end
animals=dir(tmp_data_dir);
found_it=zeros(length(ExpIDs),1);
channelFiles ={};
for ind=3:length(animals)
    if sum(found_it)== length(ExpIDs);
        break;
    end
    curr_days=dir([tmp_data_dir '\' animals(ind).name '\ImagingData']);
    for knd=3:length(curr_days)
        if sum(found_it)==length(ExpIDs);
            break;
        end
        curr_files=dir([tmp_data_dir '\' animals(ind).name '\ImagingData\' curr_days(knd).name]);
        for mnd=3:length(curr_files)
            %disp(['file:' curr_files(mnd).name])
            %if sum(found_it)==length(ExpIDs); break; end
            for lnd=1:length(ExpIDs)
                if strcmp(curr_files(mnd).name(4:7),num2str(ExpIDs{lnd}))&&~strcmp(curr_files(mnd).name(end-2:end),'ini')
                    if sum(found_it)==length(ExpIDs)
                        channelFiles = [channelFiles curr_files(mnd).name];
                    else %only update these variables for the first found channel
                        fnames{lnd}=curr_files(mnd).name;
                        mouse_id=animals(ind).name;
                        date_id=curr_days(knd).name;
                        found_it(lnd)=1;
                        channelFiles = [channelFiles curr_files(mnd).name];
                    end
                end
            end
        end
    end
end
if isempty(channelFiles)
    fprintf(2, 'no data file found in: ')
    disp([' <a href="matlab:winopen(''' tmp_data_dir stacks{stacks_ind,9} '\ImagingData\' stacks{stacks_ind,11}(1:10) '\' ''')">' tmp_data_dir stacks{stacks_ind,9} '\ImagingData\' stacks{stacks_ind,11}(1:10) '\' '</a>'])
else
    disp('data files:')
    for iFile=1:length(channelFiles)
        disp([tmp_data_dir mouse_id '\ImagingData\' date_id '\' channelFiles{iFile}])
    end
end
for ind=1:length(ExpID)
    aux_files{ind}=[mouse_id stacks{stacks_ind(ind),4} '.lvd'];
    if exist([tmp_data_dir mouse_id '\Data\' date_id '\' aux_files{ind}],'file')
        disp('aux file:')
        disp([tmp_data_dir mouse_id '\Data\' date_id '\' aux_files{ind}])
    else
        fprintf(2, 'WARNING:')
        disp(['aux file ' aux_files{ind} ' does not exist in here:'])
        disp(['<a href="matlab:winopen(''' tmp_data_dir mouse_id '\Data\' date_id '\' ''')">' tmp_data_dir mouse_id '\Data\' date_id '\' '</a>'])
    end
    stim_files{ind} = [stacks{stacks_ind(ind),11} '.txt'];
    if exist([tmp_data_dir mouse_id '\stim\' date_id '\' stim_files{ind}],'file')
        disp('stim file:')
        disp([tmp_data_dir mouse_id '\stim\' date_id '\' stim_files{ind}])
    else
        fprintf(2, 'WARNING:')
        disp(['stim file ' aux_files{ind} ' does not exist in here:'])
        disp(['<a href="matlab:winopen(''' tmp_data_dir mouse_id '\stim\' date_id '\' ''')">' tmp_data_dir mouse_id '\stim\' date_id '\' '</a>'])
    end
    
end
if ~isempty(adata_file)
    disp('Adata file exists:')
    disp([adata_dir mouse_id '\' date_id '\' adata_file])
    disp(['Load file: <a href="matlab: load(''' adata_dir mouse_id '\' date_id '\' adata_file ''')">' adata_file '</a>'])
    % load an analyze it: has ROIs has dx, dy has roi activity
    load([adata_dir mouse_id '\' date_id '\' adata_file])
    if exist('dx', 'var')
        if numel(dx) > 4
            disp('There is registration data')
        else
            fprintf(2,'Registration data has less then 5 points')
            disp(' ')
        end
    else
        fprintf(2,'No resgistration data in adata.')
    end
    if numel(fieldnames(ROIs)) == 0
        fprintf(2,'No ROI data in adata.')
        disp(' ')
    else
        disp(['number of ROIs: ' num2str(length(ROIs))] )
        if  isfield(ROIs, 'activity')
            disp('There is ROI activity data')
            disp(['Load and plot ROIs: <a href="matlab: load(''' adata_dir mouse_id '\' date_id '\' adata_file ''');plot_all_ROIs_activity(ROIs)">' adata_file '</a>'])
            if exist([tmp_data_dir mouse_id '\Data\' date_id '\' aux_files{ind}],'file') &&  exist([tmp_data_dir mouse_id '\stim\' date_id '\' stim_files{ind}],'file')
                %try to get the sync
                stim_data = loadstimdata([tmp_data_dir mouse_id '\stim\' date_id '\' stim_files{ind}]);
                tmp_data=load_lvd([tmp_data_dir mouse_id '\Data\' date_id '\' aux_files{ind}]);
                nFramesDiff=abs(length(get_frame_times(tmp_data(1,:)))-nbr_frames(ind));
                for iAuxChan=1:size(tmp_data,1)
                    tmp_frames=get_frame_times(tmp_data(iAuxChan,:));
                    frame_channel=iAuxChan;
                    if abs(length(tmp_frames)-nbr_frames(ind)) < nFramesDiff
                        % found a better match
                        nFramesDiff = abs(length(tmp_frames)-nbr_frames(ind));
                        bestMatch = iAuxChan;
                    end
                    if nFramesDiff == 0
                        %found a perfect match
                        disp(['found frame galvo signal on channel ' num2str(frame_channel)]);
                        break
                    end
                end
                if nFramesDiff ~= 0
                    fprintf(2,'Stim data does not match aux data!')
                    disp(' ')
                    
                end
            end
            
        end
    end
else
    fprintf(2,'Adata file does not exist.')
    disp(' ')
end

disp('----Done!----');

%EOF












